<template>
  <div class="review-container">
    <el-table :data="tableData" style="width: 90%; height: 90%;">
      <el-table-column fixed prop="commentid" label="ID" width="60px;"/>
      <el-table-column prop="nickname" label="nickname" width="150px;"/>
      <el-table-column prop="songname" label="songname" width="150px;"/>
      <el-table-column prop="singername" label="singername" width="150px;"/>
      <el-table-column prop="albumname" label="albumname" width="150px;"/>
      <el-table-column prop="enabled" label="enabled" width="120px;"/>
      <el-table-column prop="content" label="content"/>
      <el-table-column fixed="right" label="Operations" width="120">
        <template #default="scope">
          <el-button link v-if="scope.row.enabled" type="danger" @click="handleDisable(scope.row)"
            >Disable</el-button>
          <el-button link v-if="!scope.row.enabled" type="primary" @click="handleEnable(scope.row)"
            >Enable</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import axios from 'axios'
import { ElMessage } from 'element-plus'
export default {
  name: 'review',
  data() {
    return {
      tableData: [],
    }
  },
  methods: {
    handleDisable(row) {
      axios({
        method: 'post',
        url: '/api/disableCommentById',
        params: {
          'id': row.commentid
        }
      }).then((res) => {
        if (res.data.success) {
          ElMessage({
            message: 'Successfully Disabled',
            type: 'success'
          })
        }
      })
    },
    handleEnable(row) {
      axios({
        method: 'post',
        url: '/api/enableCommentById',
        params: {
          'id': row.commentid
        }
      }).then((res) => {
        if (res.data.success) {
          ElMessage({
            message: 'Successfully Enabled',
            type: 'success'
          })
        }
      })
    },
  },
  mounted() {
    axios({
      method: 'get',
      url: '/api/getAllComments'
    }).then((res) => {
      if (res.data.success) {
        this.$nextTick(() => {
          this.tableData = res.data.data
        })
      }
    })
  }
}
</script>

<style>
.review-container {
  display: flex;
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
}
</style>